package milkyway.hightech.formatter;

import milkyway.hightech.entry.Entry;

import java.text.DateFormat;
import java.text.NumberFormat;

import java.util.Date;
import java.util.ResourceBundle;

/**
 *
 * @author michael
 */
public class FormatterPlainText implements Formatter
{
    private StringBuffer sb = new StringBuffer();
    private ResourceBundle rb;

    @Override
    public void writeHead()
    {
    }

    /**
     *
     * @param entry
     */
    @Override
    public void formatTo(Entry entry)
    {
        Date date = entry.getDate();
        
        DateFormat dateForm =
            DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
            DateFormat.DEFAULT, rb.getLocale());

        sb.append(dateForm.format(date));
        sb.append('\n');
        sb.append(entry.getReasonOfTransfer());
        sb.append('\n');
        sb.append(entry.getSign());

        NumberFormat numberForm =
            NumberFormat.getCurrencyInstance(rb.getLocale());
        
        String value =
            numberForm.format(entry.getAmount().longValue()) + "\n\n";

        sb.append(value);
    }

    @Override
    public void writeFoot()
    {
    }

    /**
     *
     * @return
     */
    @Override
    public String getFormattedText()
    {
        return sb.substring(0);
    }

    @Override
    public void cleanUp()
    {
    }

    /**
     *
     * @param rb
     */
    @Override
    public void setLocale(ResourceBundle rb)
    {
        this.rb = rb;
    }

    /**
     *
     * @return
     */
    @Override
    public String getMimeType()
    {
        return ".txt";
    }
}